package StringDemo.demo4;

import javax.xml.transform.Result;
import java.util.Scanner;

public class AmountConversion {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int money;
        while (true) {
            System.out.println("Enter the amount to convert");
            //变量定义声明在循环外面，要不然是无效循环
            money = sc.nextInt();
            if(money >= 0 && money <= 9999999) {
                break;
            }else{
                System.out.println("Invalid input");
            }
        }
        String moneystr = "";
        //得到money里面没一位数字
        while(true){
            //从左往右获取数据
            int ge = money % 10;
            String capitalNumber = getCapitalNumber(ge);
            //把转换之后的大写拼接到moneystr当中，注意拼接顺序
            moneystr = capitalNumber + moneystr;
            //去掉刚刚获取的数据
            money = money / 10;
            if(money==0){
                break;
            }
        }
        //在前面补齐0，补齐7位
        int count = 7 - moneystr.length();
        for (int i = 0; i < count; i++) {
            moneystr = "零" + moneystr;
        }
        System.out.println(moneystr);
        //String result = "";
        //插入单位
        //定义一个数组表示单位
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};
        //遍历moneyStr，然后把arr单位依次插入
        for (int i = 0; i < moneystr.length(); i++) {
            char ch = moneystr.charAt(i);
//            for (int i = 0; i < arr.length; i++) {
//                char ch = arr[i].charAt(i);
            System.out.print(ch);
            //打印单位
            System.out.print(arr[i]);
            //通过字符串打印
            //result = result +c + arr[i];
        }
//        System.out.println(result);
    }
    //定义一个方法把数字变成大写的中文
    public static String getCapitalNumber(int number){
        //查表法！！！！！！！！
        //定义数组，让数字和大写的中文产生一个对应的关系
        String[] arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return arr[number];
    }
}
